package jp.sourceforge.akjrcp.ui;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class GenericParametersSaveDialog extends Dialog{
private String name="";
private boolean saveOverwrite;


private String windowTitle="";//Messages.getString("explorer.convertdialog")
private Text text;

private String comment="";

public void setComment(String comment) {
	this.comment = comment;
}

public String getComment() {
	return comment;
}

public String getName() {
	return name;
}

public void setName(String name) {
	this.name = name;
}

	public GenericParametersSaveDialog(Shell parentShell) {
		super(parentShell);
		
	}

	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(windowTitle);
	}
	
	public boolean isOpened(){
		return this.getShell()!=null && !this.getShell().isDisposed();
	}
protected Point getInitialSize(){
	return new Point(450,350);
	}

public void closeWindow(){
	this.close();
}

protected Control createDialogArea(Composite parent){
	/*
	 * how to limit bounds?
	 */
	Composite composite = (Composite)super.createDialogArea(parent);
	composite.setLayout(new GridLayout(1,false));
	
	
	
	Group label=new Group(composite,SWT.NULL);
	label.setText(Messages.getString("genericparameters.name"));
	label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	label.setLayout(new GridLayout());
	text = new Text(label,SWT.NULL);
	text.setText(name);
	text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	text.addModifyListener(new ModifyListener(){

		public void modifyText(ModifyEvent e) {
			setName(((Text) e.getSource()).getText());
		}
		
	});
	
	Group label2=new Group(composite,SWT.NULL);
	label2.setLayoutData(new GridData(GridData.FILL_BOTH));
	label2.setLayout(new GridLayout());
	label2.setText(Messages.getString("genericparameters.comment"));
	Text text2=new Text(label2,SWT.MULTI);
	text2.setText(comment);
	text2.setLayoutData(new GridData(GridData.FILL_BOTH));
	text2.addModifyListener(new ModifyListener(){

		public void modifyText(ModifyEvent e) {
			setComment(((Text) e.getSource()).getText());
		}
		
	});
	
	
	/*
	 * move quickly
	 */
	Composite cp=new Composite(composite,SWT.NULL);
	cp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	cp.setLayout(new GridLayout(2,true));
	Button copy=new Button(cp,SWT.RADIO);
	copy.setText(Messages.getString("genericparameters.copyandsave"));
	copy.setSelection(true);
	copy.addSelectionListener(new SelectionListener(){

		public void widgetDefaultSelected(SelectionEvent e) {
			
		}

		public void widgetSelected(SelectionEvent e) {
			saveOverwrite=false;
			text.setEnabled(true);
		}
		
	});
	
	Button save=new Button(cp,SWT.RADIO);
	save.setText(Messages.getString("genericparameters.saveoverwrite"));
	save.addSelectionListener(new SelectionListener(){

		public void widgetDefaultSelected(SelectionEvent e) {
			
		}

		public void widgetSelected(SelectionEvent e) {
			saveOverwrite=true;
			text.setEnabled(false);
		}
		
	});
	
	return composite;
}


protected void createButtonsForButtonBar(Composite parent) {
	   
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
            false);
   
    //add action?
    
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
            true);
}

public String getWindowTitle() {
	return windowTitle;
}

public void setWindowTitle(String windowTitle) {
	this.windowTitle = windowTitle;
}

public boolean isSaveOverwrite() {
	return saveOverwrite;
}

public void setSaveOverwrite(boolean saveOverwrite) {
	this.saveOverwrite = saveOverwrite;
}


}
